package com.echo.util;

import net.iharder.Base64;

public class PasswordUtil {
    public static String getBase64(String str) {  
        byte[] b = null;  
        String s = null;  
        try {  
            b = str.getBytes("utf-8");  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        if (b != null) {  
            s = Base64.encodeBytes(b); 
        }  
        return s;  
    }  

    public static String getFromBase64(String s) {  
        byte[] b = null;  
        String result = null;  
        if (s != null) {   
            try {  
                b = Base64.decode(s);  
                result = new String(b, "utf-8");  
            } catch (Exception e) {  
                e.printStackTrace();  
            }  
        }  
        return result;  
    }  
	
	public static boolean equal(String input,String rightPass){
		String value="";
		try {
			value=new String(PasswordUtil.getFromBase64(input));
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
		return value.equals(rightPass);
	}

    public static void main(String[] args){
        String str="123456";
        String str1=PasswordUtil.getBase64(str);
        String str2=PasswordUtil.getFromBase64(str1);
        System.out.println(str1);
        System.out.println(str2);
    }
}
